package com.heima.freemarker.controller;

import com.heima.freemarker.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller//这里不要带restController ，因为返回的不是一个json对象
public class FreemarkerController {

    @GetMapping("/basic")
    public String hello(Model model){
        model.addAttribute("name","freemarker");
        Student stu = new Student();
        stu.setName("小罗");
        stu.setAge(12);
        model.addAttribute("stu",stu);
        return "01-basic";
    }

    @GetMapping("/list")
    public String list(Model model){

        List<Student> list = new ArrayList<>();
        Student stu = new Student();
        stu.setName("小罗");
        stu.setAge(12);
        stu.setMoney(123.3F);
        list.add(stu);

        Student s2 =new Student();
        s2.setName("小红");
        s2.setAge(11);
        s2.setMoney(22.33F);
        list.add(s2);

        Student s3 =new Student();
        s3.setName("狗蛋");
        s3.setAge(16);
        s3.setMoney(2233.33F);
        list.add(s3);
        model.addAttribute("stus",list);

        //构建一个集合
        Map<String ,Student> map = new HashMap<>();
        map.put("stu1",stu);
        map.put("stu2",s2);
        model.addAttribute("stuMap", map);
        return "02-list-map";
    }

}
